package com.medishare.fragment;

import com.medishare.util.Utils;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;

public class ProgressDialogFragment extends DialogFragment {

	public static DialogFragment newInstance() {
		ProgressDialogFragment frag = new ProgressDialogFragment ();
		return frag;
	}
 
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
        
		
		if(!Utils.isNetworkAvailable(getActivity())){
			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			AlertDialog dialog = builder.setMessage("网络无法连接,请稍后再试")
			.setPositiveButton("确定", new OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					        dialog.dismiss();
				}
			}).create();
			dialog.setCanceledOnTouchOutside(false);
			return dialog;
		}else{
			final ProgressDialog dialog = new ProgressDialog(getActivity());
			dialog.setMessage("加载中");
			dialog.setIndeterminate(true);
			dialog.setCancelable(false);
			dialog.setCanceledOnTouchOutside(false);
			return dialog;
		}
	}
       
}
